package network;

import java.io.IOException;
import java.net.SocketException;
import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 苏西西
 * Date: 2023-10-19
 * Time: 21:55
 */
//对于DictServer来说，和EchoServer相比大部分东西都是一样的，继承复用原来的代码
//主要是根据请求计算响应这个步骤不太一样
public class UdpDictServer extends UdpEchoServer{
    private Map<String,String> dict = new HashMap<>();
    public UdpDictServer(int port) throws SocketException {
        super(port);
        //给这个dict设置一下内容
        dict.put("cat","小猫");
        dict.put("dog","小狗");
        dict.put("pig","zyt");
        //可以无限多设置

    }
    @Override
    public String process(String request){
        //查词典
        return dict.getOrDefault(request,"查不到！");

    }

    public static void main(String[] args) throws IOException {
        UdpDictServer server = new UdpDictServer(4000);
        server.start();

    }
}
